package com.ruoyi.system.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.ruoyi.system.domain.TaskLogOne;
import com.ruoyi.system.mapper.TaskLogFourMapper;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.TaskLogFour;
import com.ruoyi.system.service.ITaskLogFourService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 任务四日志Controller
 * 
 * @author ruoyi
 * @date 2024-09-18
 */
@RestController
@RequestMapping("/system/four/log")
public class TaskLogFourController extends BaseController
{
    @Autowired
    private ITaskLogFourService taskLogFourService;

    @Autowired
    private TaskLogFourMapper taskLogFourMapper;

    /**
     * 查询任务四日志列表
     */
    @PreAuthorize("@ss.hasPermi('system:fourLog:list')")
    @GetMapping("/list")
    public TableDataInfo list(TaskLogFour taskLogFour)
    {
        startPage();
        List<TaskLogFour> list = taskLogFourService.selectTaskLogFourList(taskLogFour);
        return getDataTable(list);
    }

    /**
     * 导出任务四日志列表
     */
    @PreAuthorize("@ss.hasPermi('system:fourLog:export')")
    @Log(title = "任务四日志", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TaskLogFour taskLogFour)
    {
        List<TaskLogFour> list = taskLogFourService.selectTaskLogFourList(taskLogFour);
        ExcelUtil<TaskLogFour> util = new ExcelUtil<TaskLogFour>(TaskLogFour.class);
        util.exportExcel(response, list, "任务四日志数据");
    }

    /**
     * 获取任务四日志详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:fourLog:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(taskLogFourService.selectTaskLogFourById(id));
    }

    /**
     * 新增任务四日志
     */
    @PreAuthorize("@ss.hasPermi('system:fourLog:add')")
    @Log(title = "任务四日志", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TaskLogFour taskLogFour)
    {
        return toAjax(taskLogFourService.insertTaskLogFour(taskLogFour));
    }

    /**
     * 修改任务四日志
     */
    @PreAuthorize("@ss.hasPermi('system:fourLog:edit')")
    @Log(title = "任务四日志", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TaskLogFour taskLogFour)
    {
        return toAjax(taskLogFourService.updateTaskLogFour(taskLogFour));
    }

    /**
     * 删除任务四日志
     */
    @PreAuthorize("@ss.hasPermi('system:fourLog:remove')")
    @Log(title = "任务四日志", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(taskLogFourService.deleteTaskLogFourByIds(ids));
    }


    /**
     * 查询任务四日志 主任务关联的列表
     */
//    @PreAuthorize("@ss.hasPermi('system:oneLog:list')")
    @PostMapping("/taskLogList")
    public AjaxResult taskLogList(@RequestBody TaskLogFour taskLogFour)
    {
//        QueryWrapper<TaskLogFour> queryWrapper = new QueryWrapper<TaskLogFour>();
//        queryWrapper.select("id","task_id","type","title","content","operator_name","operator_time")
//                .eq("task_id", taskLogFour.getTaskId())
//                .eq("type",0);

        List<TaskLogFour> taskLogFours = taskLogFourMapper.selectTaskLogFourListByLog(taskLogFour);

        return AjaxResult.success(taskLogFours);
    }
}
